package com.lagou.demo.controller;

import com.lagou.demo.service.IDemoService;
import com.lagou.mvcframework.annotations.LagouAutowired;
import com.lagou.mvcframework.annotations.LagouController;
import com.lagou.mvcframework.annotations.LagouRequestMapping;
import com.lagou.mvcframework.annotations.LagouSecurity;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@LagouSecurity({"zhangsan","liufh"})
@LagouController
@LagouRequestMapping("/demo")
public class DemoController {

    @LagouAutowired
    private IDemoService demoService;

    /**
     * URL: /demo/query?username=lisi
     * @param request
     * @param response
     * @param username
     * @return
     */
    @LagouRequestMapping("/query")
    public void query(HttpServletRequest request, HttpServletResponse response, String username) throws IOException {
        demoService.get(username);
        response.getWriter().write("success!");
//        return demoService.get(username);
    }

    /**
     * URL: /demo/querySecurity01?username=lisi
     */
    @LagouSecurity("lisi")
    @LagouRequestMapping("/querySecurity01")
    public void querySecurity01(HttpServletRequest request, HttpServletResponse response, String username) throws IOException {
        demoService.get(username);
        response.getWriter().write("success!");
    }

    /**
     * URL: /demo/querySecurity02?username=wangwu
     */
    @LagouSecurity("wangwu")
    @LagouRequestMapping("/querySecurity02")
    public void querySecurity02(HttpServletRequest request, HttpServletResponse response, String username) throws IOException {
        demoService.get(username);
        response.getWriter().write("success!");
    }

}
